﻿using B.S.Sterilizationcenter.Domain.zmc;
using B.S.Sterilizationcenter.ErrorCode;
using B.S.Sterilizationcenter.Read.API.Appliaction.Commends.zmc.Warehou;
using B.S.Sterilizationcenter.Read.API.Dto;
using MediatR;
using SqlSugar;
using System.Data.SqlTypes;

namespace B.S.Sterilizationcenter.Read.API.Appliaction.CommandHandlers.zmc.Warehou
{
    public class QueryWarehousdetailsrecordStuffCommendhandlers : IRequestHandler<QueryWarehousdetailsrecordStuffCommends, ApiResult<List<warehousStuDto>>>
    {

        private readonly ISqlSugarClient db;

        public QueryWarehousdetailsrecordStuffCommendhandlers(ISqlSugarClient db)
        {
            this.db = db;
        }


        /// <summary>
        /// 查询仓入库详情记录信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<ApiResult<List<warehousStuDto>>> Handle(QueryWarehousdetailsrecordStuffCommends request, CancellationToken cancellationToken)
        {
            ApiResult<List<warehousStuDto>> result = new ApiResult<List<warehousStuDto>>();
            result.Code = ApiEnums.查询成功;
            result.Msg= "查询成功";
            var list =  db.Queryable<Stuff>().LeftJoin<Warehous>((a, b) => a.WarehousNo == b.WarehousNo).Select((a, b) => new warehousStuDto
            {
                StuffId = a.StuffId,
                StuffName = a.StuffName,
                Specifica = a.Specifica,
                Unit = a.Unit,
                Deliveryquans = a.Deliveryquans,
                WarehousNo = b.WarehousNo,
                Incomquans = a.Incomquans,
                StorageDate = a.StorageDate,
                OutboundNo = a.OutboundNo,
                AuditDate = b.AuditDate,
                WarehousName = b.WarehousName,
                ReceivDate = b.ReceivDate,
                DeliveryDate = b.DeliveryDate,
                Status = b.Status,
                WarehousId = b.WarehousId,


            }).ToList();
            result.Data = list;
            return result;
        }
    }
}
